<template>
  <!--  一二 三 级分类-->
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select style="width: 220px" v-model="CategoryStore.C1Id" @change='handle'>
          <el-option
            v-for="(c1, index) in CategoryStore.ArrC1"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select style="width: 220px" v-model='CategoryStore.C2Id' @change='handle1'>
          <el-option v-for='(c2,index) in CategoryStore.ArrC2' :key='c2.id' :label='c2.name' :value='c2.id'></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select style="width: 220px" v-model='CategoryStore.C3Id'>
          <el-option v-for='(c3,index) in CategoryStore.ArrC3' :key='c3.id' :label='c3.name' :value='c3.id'></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
//引入生命周期
import { onMounted } from 'vue'
//引入厂库
import useCategoryStore from '@/store/modules/category'
let CategoryStore = useCategoryStore()
//生命周期挂载
onMounted(() => {
  getC1()
})
//通知仓库获取一级分类的方法的
const getC1 = () => {
  CategoryStore.getC1()
}

//一级分类触发二级分
const handle=()=>{
  //清除二三级的数据与id
  CategoryStore.C2Id=''
  CategoryStore.C3Id=''
  CategoryStore.ArrC3=''
  CategoryStore.getC2()
}
//二级分类下的三级分类
const handle1=()=>{
  //清空三级分类的Id
  CategoryStore.C3Id=''
  CategoryStore.getC3()
}
</script>

<style scoped lang="scss"></style>
